import React from "react"
import Modal from 'antd/lib/modal/Modal'
import {connect} from 'umi'
import {Form,Input,Select,DatePicker} from "antd"
import moment from 'moment'
const {Option}=Select
const Search=(props:any)=>{
    const {showSearch}=props
    const [form]=Form.useForm()
    const {dispatch,model}=props
    const onCancel=()=>{
        dispatch({
            type: "airlineInfo/save",
            payload: {
                showEdit: false,
                isEdit:false,
                showSearch:false
            }
        })
    }
    const onFinish=()=>{
            form.validateFields().then((values)=>{
                console.log(values)
                let {s_time}=values
                values={...values,s_time:s_time.format('YYYY-MM-DD')}
                dispatch({
                    type:"airlineInfo/search",
                    payload:{
                        data:{...values}
                    }
                })
            })
    }
    return ( 
        <Modal visible={showSearch}  getContainer={false} title="查询" onCancel={onCancel} onOk={onFinish} >
            <Form form={form} onFinish={onFinish}>
            <Form.Item label="航班号" name="flight_id" rules={[{message:"请输入需要查询的航班号"}]}>    
                <Input placeholder="请输入航班号"/>  
            </Form.Item>
            <Form.Item label="出发地点" name="s_loc_id" rules={[{message:"请选择出发地点"}]}> 
                <Select placeholder="请选择出发地">
                    <Option value="1">武汉</Option>
                    <Option value="2">杭州</Option>
                </Select>
            </Form.Item>
            <Form.Item label="起飞日期"　name="s_time" rules={[{required:true,message:"请选择出发地点"}]}  > 
                <DatePicker format="YYYY-MM-DD"/>
            </Form.Item>
            </Form>
        </Modal>
    )
}
const mapStateToProps=(state:any)=>({
    model:state.airlineInfo.current,
    showSearch:state.airlineInfo.showSearch
})
export default connect(mapStateToProps)(Search)